home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!chi-il9-08
- From: stefmit@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Working through C++ - some help needed
- Date: 27 Mar 1996 04:50:33 GMT
- Organization: Netcom
- Message-ID: <4jahep$b34@dfw-ixnews2.ix.netcom.com>
- References: <3158EDE7.2C27@intercom.com>
- NNTP-Posting-Host: chi-il9-08.ix.netcom.com
- X-NETCOM-Date: Tue Mar 26 10:50:33 PM CST 1996
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <3158EDE7.2C27@intercom.com>, access <access@intercom.com> wrote:
- >Working my way through the "forest" of C++, I try to work on an exercise
- >that is more like invented, than a proven workable problem - but I
- >thought of being of help in understanding different concepts in C++. I am
- >trying to build the followings (based on classes, rather than one
- >single lenghty algorithm):
- >- An array list (having the regular functions, like the ones shown
- >everywhere in the books: get, put, moveto, gotostart, gotoend, etc.),
- >which will contain a different queue in each of its elements, queues
- >being distinguished by a number (with pop and push functions, at least)
- >which queue will contain nodes (... remember the Russian dols :-) ...),
- >and each node will contain a couple of the most significant elements of
- >C++ (a char, an int, a string, for example).
- >Now, being said the above, I don't know how to start building and how to
- >access the elements of each node (I don't even know if it is possible)
- >either by user input or from a file. What I try actually would be
- >something like: given an element with the int as the array element where
- >its queue is to be placed, how do I actually put it there using the
- >normal messages such constructions would come with (like: read the whole
- >element from a file as a string which has the data separated by blanks -
- >int, char and string, then taking the int and deciding what element in
- >the array it is going to go into, then taking the char and the string and
- >building the actual element and attaching it to the queue in the decided
- >array element). Did anybody make any sense out of this? If the answer is
- >YES, would any kind soul enlighten me on whether this would be possible
- >to build, and actually how to manipulate the messages of the different
- >classes I see being built (class array_list, class My_queue and class
- >My_queue_node) to put/remove the elements?
- >Thanks a lot to whoever had the patience to read through this lenghty and
- >senseless message, and mostly to whoever would care to answer me if this
- >is "mission impossible".
- >
- >Sleepless_C++
-
- That's an interesting subject (for a beginner, like myself). I will "bite":
-
- What about the following classes:
-
- class My_elem_in_node
- {private: int my_number;
- char my_char;
- char *my_strg_ptr;
- public: int get_my_number ();
- char get_my_char();
- char *get_my_strg();
- // a constructor
- // a destructor
- void set_my_number (int &new_number) const;
- void set_my_char (char &new_char) const;
- void *set_my_strg (char *new_strg); }
-
- template <my_type_above>
- class My_queue_node
- {private: My_queue_node (const my_type_above &new_element, My_queue_node
- *next_ptr)
- public: my_type_above node_element;
- My_queue_node *next;
- friend class My_queue <my_type_above>; }
-
- template <class my_type_above>
- class My_queue
- {public: My_queue();
- ~My_queue();
- void enqueue (const my_type_above &new_node)
- my_type_above dequeue();
- // others, like clear(), isempty(), isfull(), display(), etc.
- private: My_queue_node <my_type_above> *head, *tail; }
-
- template <class my_type_above>
- class my_array
- {public: my_array (int max_nb_of_elements = 10);
- ~my_array();
- void insert (const my_type_above &new_array_element);
- void remove ();
- // and others (perhaps a clear (), is_empty(), is_full(), etc.)
- private: int max_array_size;
- int size_array;
- int cursor; // to go through array
- my_type_above *array_element; }
-
- class strg_manipulator // for whatever string you're getting from a file/user
- {private: char *strg_content;
- public: strg_manipulator (char *string_in = 0);
- ~strg_manipulator ();
- char *get_user_strg ();
- void *set_user_strg (char *string_in); }
-
- For sure other classes will fit here, like file I/O processing (read, save),
- etc.
- I hope this helps, but definitely doesn't fully answer your question. I told
- you I am a beginner myself :-). Perhaps somebody will care to correct or
- complete me with how to put these pieces together.
-
- PS - You might want to check your e-mail address - it bounces back when I try
- to e-mail you.
-
- Cheers,
- Stefan
-